package hiresoft.ui;

import hiresoft.network.*;
import hiresoft.users.Recruiter;
import java.util.ArrayList;
import javax.swing.*;

/**
 * Creates the User Interface and
 *  functionality for Recruiter accounts
 *
 * @author Jan Jorgensen
 * @author Kevin Carlino
 */
public class RecruiterFrame extends UserFrame {
    DefaultListModel model;
    int doDelete;
    boolean createAccount;
    Network net;
    private ArrayList<Integer> jobID;
    private ArrayList<Integer> jobID2;
    private ArrayList<Integer> revID2;
    private ArrayList<Integer> appID;
    private ArrayList<Integer> revID;
    private int selectedApplicantID;

    public RecruiterFrame(LoginFrame context, Recruiter _user){
        super(context, _user);
        initComponents();
        revID = new ArrayList<Integer>();
        appID = new ArrayList<Integer>();

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabs = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        lblDescription = new javax.swing.JLabel();
        lblJobID = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstPostings = new javax.swing.JList();
        lblDeadline = new javax.swing.JLabel();
        lblRequirements = new javax.swing.JLabel();
        lblID = new javax.swing.JLabel();
        btnApply = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtRequirements = new javax.swing.JTextArea();
        btnCancel = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtDescription = new javax.swing.JTextArea();
        subtractButton = new javax.swing.JButton();
        deadlineField = new java.awt.TextField();
        addButton = new javax.swing.JButton();
        titleField = new java.awt.TextField();
        payField = new java.awt.TextField();
        lblPay = new javax.swing.JLabel();
        lblJobTitle = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblApplicantName = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtResume = new javax.swing.JTextArea();
        lblJobTitle1 = new javax.swing.JLabel();
        lblResume = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        lstPostings1 = new javax.swing.JList();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        txtReference2 = new javax.swing.JTextArea();
        jScrollPane7 = new javax.swing.JScrollPane();
        txtReference3 = new javax.swing.JTextArea();
        lblReference3 = new javax.swing.JLabel();
        lblReference1 = new javax.swing.JLabel();
        lblReference2 = new javax.swing.JLabel();
        jScrollPane9 = new javax.swing.JScrollPane();
        txtReference1 = new javax.swing.JTextArea();
        btnAddReviewer = new javax.swing.JButton();
        deleteReviewer = new javax.swing.JButton();
        jScrollPane12 = new javax.swing.JScrollPane();
        lstReviewers = new javax.swing.JList();
        jScrollPane11 = new javax.swing.JScrollPane();
        lstApplications = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        lblAvgRating = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        lblComments = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        txtComments = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        lblReviewerRating = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        txtUsername = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        lblID1 = new javax.swing.JLabel();
        lblUsername = new javax.swing.JLabel();
        lblPassword = new javax.swing.JLabel();
        txtPassword = new javax.swing.JTextField();
        jScrollPane10 = new javax.swing.JScrollPane();
        lstAccounts = new javax.swing.JList();
        btnAdd = new javax.swing.JButton();
        btnSubmit = new javax.swing.JButton();
        btnCancel2 = new javax.swing.JButton();
        chkDelete = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        tabs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabsMouseClicked(evt);
            }
        });
        tabs.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabsStateChanged(evt);
            }
        });

        lblDescription.setText("Description");

        lblJobID.setText("Job ID:");

        lstPostings.setModel(new DefaultListModel());
        lstPostings.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstPostingsMouseClicked(evt);
            }
        });
        lstPostings.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstPostingsValueChanged(evt);
            }
        });
        lstPostings.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                lstPostingsKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                lstPostingsKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(lstPostings);

        lblDeadline.setText("Deadline:");

        lblRequirements.setText("Requirements");

        lblID.setText("Automatically Assigned");

        btnApply.setText("Apply");
        btnApply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnApplyActionPerformed(evt);
            }
        });

        txtRequirements.setColumns(20);
        txtRequirements.setRows(5);
        txtRequirements.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtRequirementsFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtRequirementsFocusLost(evt);
            }
        });
        jScrollPane3.setViewportView(txtRequirements);

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        txtDescription.setColumns(20);
        txtDescription.setRows(5);
        txtDescription.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtDescriptionFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDescriptionFocusLost(evt);
            }
        });
        jScrollPane2.setViewportView(txtDescription);

        subtractButton.setText("-");
        subtractButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subtractButtonActionPerformed(evt);
            }
        });

        deadlineField.setText("Enter Deadline");
        deadlineField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                deadlineFieldMouseClicked(evt);
            }
        });
        deadlineField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deadlineFieldActionPerformed(evt);
            }
        });
        deadlineField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                deadlineFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                deadlineFieldFocusLost(evt);
            }
        });

        addButton.setText("+");
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });

        titleField.setText("Enter Job Title");
        titleField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                titleFieldMouseClicked(evt);
            }
        });
        titleField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                titleFieldActionPerformed(evt);
            }
        });
        titleField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                titleFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                titleFieldFocusLost(evt);
            }
        });

        payField.setText("Enter Pay Rate");
        payField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                payFieldActionPerformed(evt);
            }
        });
        payField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                payFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                payFieldFocusLost(evt);
            }
        });

        lblPay.setText("Pay:");

        lblJobTitle.setText("Job Title:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblDescription)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lblJobTitle)
                                            .addComponent(lblPay))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(payField, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                                .addGap(18, 18, 18)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblRequirements)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lblDeadline)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(deadlineField, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(lblJobID)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 110, Short.MAX_VALUE)
                                .addComponent(lblID))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(subtractButton, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnApply, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblJobTitle)
                                .addComponent(lblJobID)
                                .addComponent(lblID))
                            .addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lblPay)
                                        .addComponent(lblDeadline))
                                    .addComponent(deadlineField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(38, 38, 38)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblRequirements)
                                    .addComponent(lblDescription)))
                            .addComponent(payField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(subtractButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnApply, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        tabs.addTab("Job Postings", jPanel1);

        lblApplicantName.setText("Applicant Name");

        txtResume.setColumns(20);
        txtResume.setEditable(false);
        txtResume.setRows(5);
        jScrollPane4.setViewportView(txtResume);

        lblJobTitle1.setText("Job Title");

        lblResume.setText("Resume");

        lstPostings1.setModel(new DefaultListModel());
        lstPostings1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstPostings1MouseClicked(evt);
            }
        });
        lstPostings1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstPostings1ValueChanged(evt);
            }
        });
        lstPostings1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                lstPostings1KeyReleased(evt);
            }
        });
        jScrollPane5.setViewportView(lstPostings1);

        txtReference2.setColumns(20);
        txtReference2.setEditable(false);
        txtReference2.setRows(5);
        txtReference2.setText("Reference2's input");
        jScrollPane6.setViewportView(txtReference2);

        txtReference3.setColumns(20);
        txtReference3.setEditable(false);
        txtReference3.setRows(5);
        txtReference3.setText("Reference3's input");
        jScrollPane7.setViewportView(txtReference3);

        lblReference3.setText("Reference 3");

        lblReference1.setText("Reference 1");

        lblReference2.setText("Reference 2");

        txtReference1.setColumns(20);
        txtReference1.setEditable(false);
        txtReference1.setRows(5);
        txtReference1.setText("Reference1's input");
        jScrollPane9.setViewportView(txtReference1);

        btnAddReviewer.setText("Add Reviewer");
        btnAddReviewer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddReviewerActionPerformed(evt);
            }
        });

        deleteReviewer.setText("Remove Reviewer");
        deleteReviewer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteReviewerActionPerformed(evt);
            }
        });

        lstReviewers.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstReviewersValueChanged(evt);
            }
        });
        jScrollPane12.setViewportView(lstReviewers);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                            .addComponent(lblReference3, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                            .addComponent(lblReference1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblReference2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(btnAddReviewer, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(deleteReviewer, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane12, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(lblReference1)
                .addGap(2, 2, 2)
                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblReference2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblReference3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAddReviewer)
                    .addComponent(deleteReviewer))
                .addContainerGap(320, Short.MAX_VALUE))
        );

        lstApplications.setModel(new DefaultListModel());
        lstApplications.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstApplicationsMouseClicked(evt);
            }
        });
        lstApplications.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstApplicationsValueChanged(evt);
            }
        });
        lstApplications.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                lstApplicationsKeyReleased(evt);
            }
        });
        jScrollPane11.setViewportView(lstApplications);

        jLabel2.setText("Avg Rating");

        lblAvgRating.setText("X.XX");

        lblEmail.setText("Email");

        lblComments.setText("Comments");

        txtComments.setColumns(20);
        txtComments.setEditable(false);
        txtComments.setRows(5);
        txtComments.setText("Reviwer Comments");
        jScrollPane8.setViewportView(txtComments);

        jLabel3.setText("Reviewer Rating:");

        lblReviewerRating.setText("X.XX");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblJobTitle1)
                                    .addComponent(lblApplicantName))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                                .addComponent(lblEmail))
                            .addComponent(lblResume, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblComments, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblAvgRating)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addGap(11, 11, 11)
                        .addComponent(lblReviewerRating)
                        .addGap(10, 10, 10)))
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblApplicantName)
                                    .addComponent(lblEmail))
                                .addGap(31, 31, 31)
                                .addComponent(lblJobTitle1)
                                .addGap(18, 18, 18)
                                .addComponent(lblResume)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblComments)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(lblReviewerRating)
                                    .addComponent(lblAvgRating))))
                        .addGap(319, 319, 319)))
                .addGap(11, 11, 11))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 555, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        tabs.addTab("Applications", jPanel2);

        jLabel1.setText("Account ID:");

        lblID1.setText("0");

        lblUsername.setText("Username");

        lblPassword.setText("Password");

        lstAccounts.setModel(new DefaultListModel());
        lstAccounts.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstAccountsValueChanged(evt);
            }
        });
        jScrollPane10.setViewportView(lstAccounts);

        btnAdd.setText("New Account");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnSubmit.setText("Submit");
        btnSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubmitActionPerformed(evt);
            }
        });

        btnCancel2.setText("Cancel");
        btnCancel2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancel2ActionPerformed(evt);
            }
        });

        chkDelete.setText("Delete Account?");
        chkDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAdd, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(247, 247, 247)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(lblID1))
                            .addComponent(lblUsername)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtUsername, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblPassword, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(chkDelete, javax.swing.GroupLayout.Alignment.LEADING)))
                        .addContainerGap(315, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(btnSubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancel2, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(lblID1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblUsername)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(21, 21, 21)
                        .addComponent(lblPassword)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(chkDelete))
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd)
                    .addComponent(btnCancel2)
                    .addComponent(btnSubmit))
                .addContainerGap())
        );

        tabs.addTab("Accounts", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 870, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, 590, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void payFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_payFieldActionPerformed
        // TODO add your handling code here:
        if(payField.getText().equalsIgnoreCase("Enter Pay Rate"))
            payField.setText("");
}//GEN-LAST:event_payFieldActionPerformed

    private void titleFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_titleFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_titleFieldActionPerformed

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        lstPostings.setEnabled(false);
        addButton.setEnabled(false);
        subtractButton.setEnabled(false);
        tabs.setEnabled(false);
        model = ((DefaultListModel)lstPostings.getModel());
        model.addElement("New Job");
        lstPostings.setSelectedIndex(model.size() - 1);
        titleField.setText("Enter Job Title");
        payField.setText("Enter Pay Rate");
        deadlineField.setText("Enter Deadline");
        txtDescription.setText("Enter Job Description");
        txtRequirements.setText("Enter Job Requirements");
}//GEN-LAST:event_addButtonActionPerformed

    private void deadlineFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deadlineFieldActionPerformed
        // TODO add your handling code here:
        if(payField.getText().equalsIgnoreCase("Enter Deadline"))
            payField.setText("");
}//GEN-LAST:event_deadlineFieldActionPerformed

    private void subtractButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subtractButtonActionPerformed
        int selJobID = lstPostings.getSelectedIndex();

        if(selJobID > -1) {
            try {
                net.out.Insert(jobID.get(selJobID));
                net.out.Send(Packets.P_DELETEJOB);

                if (net.Ready()) {
                    if (net.in.getPacketId() == Packets.P_DELETEJOB) {
                        if(net.in.getDWord() !=0) {
                            JOptionPane.showMessageDialog(null, "Job successfully deleted.");
                            model = ((DefaultListModel)lstPostings.getModel());
                            if(selJobID > 0){
                                lstPostings.setSelectedIndex(selJobID - 1);
                            }else if(selJobID + 1 < model.size()){
                                lstPostings.setSelectedIndex(selJobID + 1);
                            }
                            lblID.setText("0");
                            lblJobTitle.setText("");
                            lblPay.setText("");
                            lblDeadline.setText("");
                            model.removeElementAt(selJobID);
                            getJob();
                        } else
                            JOptionPane.showMessageDialog(null, "Failed to delete job.");
                    }
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error: " + e);
            }
        }
}//GEN-LAST:event_subtractButtonActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        int selJobID = lstPostings.getSelectedIndex();

        boolean newJob = (selJobID==jobID.size());

        if(newJob){
            model = ((DefaultListModel)lstPostings.getModel());
            model.removeElementAt(selJobID);
            lstPostings.setEnabled(true);
            addButton.setEnabled(true);
            subtractButton.setEnabled(true);
            tabs.setEnabled(true);
            lstPostings.setSelectedIndex(selJobID - 1);
            getJob();
        }else{
            getJob();
        }
}//GEN-LAST:event_btnCancelActionPerformed

    private void btnApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnApplyActionPerformed
        int selJobID = lstPostings.getSelectedIndex();

        if(selJobID > -1) {
            try {
                boolean newJob = (selJobID==jobID.size());
                if(newJob){
                    net.out.Insert(0);
                } else{
                    net.out.Insert(jobID.get(selJobID));
                }
                net.out.Insert(titleField.getText());
                net.out.Insert(payField.getText());
                net.out.Insert(deadlineField.getText());
                net.out.Insert(txtDescription.getText());
                net.out.Insert(txtRequirements.getText());
                net.out.Send(Packets.P_EDITJOB);

                if (net.Ready()) {
                    if (net.in.getPacketId() == Packets.P_EDITJOB) {
                        int response = net.in.getDWord();
                        if(response !=0) {
                            if(!newJob){
                                JOptionPane.showMessageDialog(null, "Your changes have been saved.");
                                model.set(selJobID, titleField.getText());
                                lblID.setText(net.in.getDWord() + "");
                            }else{
                                JOptionPane.showMessageDialog(null, "Your new job has been posted.");
                                jobID.add(response);
                                model = ((DefaultListModel)lstPostings.getModel());
                                model.set(selJobID, titleField.getText());

                                lstPostings.setEnabled(true);
                                addButton.setEnabled(true);
                                subtractButton.setEnabled(true);
                                tabs.setEnabled(true);
                            }
                        } else
                            JOptionPane.showMessageDialog(null, "Failed to submit changes.");
                    }
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
            }
        }
}//GEN-LAST:event_btnApplyActionPerformed

    private void lstPostingsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lstPostingsKeyReleased
        if(lstPostings.isEnabled())
            getJob();
}//GEN-LAST:event_lstPostingsKeyReleased

    private void lstPostingsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lstPostingsKeyPressed

}//GEN-LAST:event_lstPostingsKeyPressed

    private void lstPostingsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstPostingsValueChanged
        if(lstPostings.isEnabled())
            getJob();
}//GEN-LAST:event_lstPostingsValueChanged

    private void lstPostingsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstPostingsMouseClicked
        if(lstPostings.isEnabled())
            getJob();
}//GEN-LAST:event_lstPostingsMouseClicked

    private void lstApplicationsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstApplicationsMouseClicked

    }//GEN-LAST:event_lstApplicationsMouseClicked

    private void lstApplicationsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lstApplicationsKeyReleased
        
    }//GEN-LAST:event_lstApplicationsKeyReleased

    private void tabsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabsMouseClicked

    }//GEN-LAST:event_tabsMouseClicked

    private void btnAddReviewerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddReviewerActionPerformed
        if(lstApplications.getSelectedIndex()==-1){
            JOptionPane.showMessageDialog(null, "No application selected");
        }else{
        try {
            net.out.Send(Packets.P_GETALLREVIEWERS);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETALLREVIEWERS)
                {
                        if(net.in.getDWord() != 0)
                        {
                            int revNums = net.in.getDWord();
                            int[] temprevID = new int[revNums];
                            ArrayList<String> temprevNames = new ArrayList<String>();
                            for(int i = 0; i < revNums; i++)
                            {
                                temprevID[i] = net.in.getDWord();
                                temprevNames.add(net.in.getString());
                            }

                            String selectedValue = (String) JOptionPane.showInputDialog(null,
                                                    "Choose reviewer to add", "Input",
                                                    JOptionPane.INFORMATION_MESSAGE, null,
                                                    temprevNames.toArray(), temprevNames.get(0));
                            if(selectedValue != null){
                            net.out.Insert(appID.get(lstApplications.getSelectedIndex()));
                            net.out.Insert(selectedValue);
                            net.out.Send(Packets.P_ADDREVIEWER);

                            if(net.Ready()){
                                if(net.in.getPacketId() == Packets.P_ADDREVIEWER){
                                    if(net.in.getDWord() != 0){
                                        JOptionPane.showMessageDialog(null, "Successfully added reviewer");
                                        getApplication();
                                    }else{
                                        JOptionPane.showMessageDialog(null, "Reviewer not added");
                                    }
                                }
                            }
                            }
                        }
                        else
                            JOptionPane.showMessageDialog(null, "Failed to retrieve account listing.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
    }
    }//GEN-LAST:event_btnAddReviewerActionPerformed

    private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
        int selAccID = lstAccounts.getSelectedIndex();
        model = ((DefaultListModel)lstAccounts.getModel());

        if(selAccID > -1) {
            if(doDelete == 0) {
                try {
                        net.out.Insert(Integer.parseInt(lblID1.getText()));
                        net.out.Insert(txtUsername.getText());
                        net.out.Insert(txtPassword.getText());
                        net.out.Send(Packets.P_EDITREVIEWERACCOUNT);

                        if (net.Ready())
                        {
                            if (net.in.getPacketId() == Packets.P_EDITREVIEWERACCOUNT)
                            {
                                if(net.in.getDWord() != 0)
                                {
                                    int newID = net.in.getDWord();
                                    revID.add(newID);
                                    JOptionPane.showMessageDialog(null, "The account has been edited successfully.");
                                }
                                else
                                    JOptionPane.showMessageDialog(null, "Failed to edit account.");
                            }
                        }
                    }
                    catch (Exception e) {
                        JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
                    }
            }
            else {
                try {
                        net.out.Insert(Integer.parseInt(lblID1.getText()));
                        net.out.Send(Packets.P_DELETEREVIEWERACCOUNT);

                        if (net.Ready())
                        {
                            if (net.in.getPacketId() == Packets.P_DELETEREVIEWERACCOUNT)
                            {
                                if(net.in.getDWord() != 0)
                                {
                                    JOptionPane.showMessageDialog(null, "The account has been deleted successfully.");
                                }
                                else
                                    JOptionPane.showMessageDialog(null, "Failed to delete account.");
                            }
                        }
                    }
                    catch (Exception e) {
                        JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
                    }
            }
        }
        else {
            JOptionPane.showMessageDialog(null, "You do not have a Reviewer selected.");
        }
        if(createAccount) {
            lstAccounts.setEnabled(true);
            btnAdd.setEnabled(true);
            chkDelete.setEnabled(true);
            btnCancel2.setEnabled(false);
        }
        if(doDelete == 1) {
            doDelete = 0;
            chkDelete.setSelected(false);
            txtUsername.setEnabled(true);
            txtUsername.setText("");
            txtPassword.setEnabled(true);
            txtPassword.setText("");
            lblID1.setText("0");
        }
        model.clear();
        getAccs();
    }//GEN-LAST:event_btnSubmitActionPerformed

    private void btnCancel2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancel2ActionPerformed
        model = ((DefaultListModel)lstAccounts.getModel());
        createAccount = true;

        model.removeElement("New Account");
        lstAccounts.setEnabled(true);
        btnAdd.setEnabled(true);
        lstAccounts.setSelectedIndex(model.size() - 1);
        txtUsername.setText("");
        txtPassword.setText("");
        lblID1.setText("0");
        chkDelete.setEnabled(true);
        btnCancel2.setEnabled(false);
    }//GEN-LAST:event_btnCancel2ActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        model = ((DefaultListModel)lstAccounts.getModel());
        createAccount = true;

        model.addElement("New Account");
        lstAccounts.setEnabled(false);
        btnAdd.setEnabled(false);
        lstAccounts.setSelectedIndex(model.size() - 1);
        txtUsername.setText("Enter Username");
        txtPassword.setText("Enter Password");
        lblID1.setText("0");
        chkDelete.setEnabled(false);
        btnCancel2.setEnabled(true);
    }//GEN-LAST:event_btnAddActionPerformed

    private void tabsStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabsStateChanged
        if(net != null) {
            switch(tabs.getSelectedIndex()) {
                    case 0: getPosts();
                            break;
                    case 1: getPosts1();
                            break;
                    case 2: getAccs();
                            break;
                    default: break;
                }
        }
    }//GEN-LAST:event_tabsStateChanged

    private void lstAccountsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstAccountsValueChanged
        if(lstAccounts.isEnabled() && lstAccounts.getValueIsAdjusting())
            getAcc();
    }//GEN-LAST:event_lstAccountsValueChanged

    private void lstApplicationsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstApplicationsValueChanged
        if(lstApplications.isEnabled() && lstApplications.getValueIsAdjusting()){
            getApplication();
            getRating();
        }
    }//GEN-LAST:event_lstApplicationsValueChanged

    private void lstPostings1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lstPostings1KeyReleased

}//GEN-LAST:event_lstPostings1KeyReleased

    private void lstPostings1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstPostings1ValueChanged
        if(lstPostings1.getValueIsAdjusting()) {
            getJob1();
            lstApplications.setEnabled(true);
        }
}//GEN-LAST:event_lstPostings1ValueChanged

    private void lstPostings1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstPostings1MouseClicked

}//GEN-LAST:event_lstPostings1MouseClicked

    private void chkDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkDeleteActionPerformed
        if(doDelete == 1) {
            doDelete = 0;
            txtUsername.setEnabled(true);
            txtPassword.setEnabled(true);
        }
        else {
            doDelete = 1;
            txtUsername.setEnabled(false);
            txtPassword.setEnabled(false);
        }
    }//GEN-LAST:event_chkDeleteActionPerformed

    private void deleteReviewerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteReviewerActionPerformed
        // TODO add your handling code here:
        int revSelection = lstReviewers.getSelectedIndex();
        int appSelection = lstApplications.getSelectedIndex();
        if(appSelection==-1){
            JOptionPane.showMessageDialog(null, "No application selected");
        }else if(revSelection==-1){
            JOptionPane.showMessageDialog(null, "No reviewer selected");            
        } else {
            try{
                net.out.Insert(appID.get(appSelection));
                net.out.Insert((String) ((DefaultListModel) lstReviewers.getModel()).get(revSelection));
                net.out.Send(Packets.P_DELETEREVIEWER);

                if(net.Ready()){
                    if(net.in.getPacketId() == Packets.P_DELETEREVIEWER){
                        if(net.in.getDWord() != 0){
                            JOptionPane.showMessageDialog(null, "Reviewer deleted.");
                            ((DefaultListModel) lstReviewers.getModel()).remove(revSelection);
                            
                        }else{
                            JOptionPane.showMessageDialog(null, "Error removing reviewer.");
                        }
                    }
                }
            }catch(Exception e){
                JOptionPane.showMessageDialog(null, "Error deleting job: " + e);
                e.printStackTrace();
            }
            
        }
    }//GEN-LAST:event_deleteReviewerActionPerformed

    private void lstReviewersValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstReviewersValueChanged
        // TODO add your handling code here:
        getRating();
    }//GEN-LAST:event_lstReviewersValueChanged

    private void titleFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titleFieldMouseClicked

    }//GEN-LAST:event_titleFieldMouseClicked

    private void deadlineFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_deadlineFieldMouseClicked

    }//GEN-LAST:event_deadlineFieldMouseClicked

    private void titleFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_titleFieldFocusGained
        // TODO add your handling code here:
        if(titleField.getText().equals("Enter Job Title")){
            titleField.setText(null);
        }
    }//GEN-LAST:event_titleFieldFocusGained

    private void payFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_payFieldFocusGained
        // TODO add your handling code here:
        if(payField.getText().equals("Enter Pay Rate")){
            payField.setText(null);
        }
    }//GEN-LAST:event_payFieldFocusGained

    private void deadlineFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_deadlineFieldFocusGained
        // TODO add your handling code here:
        if(deadlineField.getText().equals("Enter Deadline"))
            deadlineField.setText(null);
    }//GEN-LAST:event_deadlineFieldFocusGained

    private void txtDescriptionFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescriptionFocusGained
        if (txtDescription.getText().equals("Enter Job Description"))
            txtDescription.setText(null);
    }//GEN-LAST:event_txtDescriptionFocusGained

    private void txtRequirementsFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtRequirementsFocusGained
        if (txtRequirements.getText().equals("Enter Job Requirements"))
            txtRequirements.setText(null);
    }//GEN-LAST:event_txtRequirementsFocusGained

    private void titleFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_titleFieldFocusLost
        if(titleField.getText().isEmpty()){
            titleField.setText("Enter Job Title");
        }
    }//GEN-LAST:event_titleFieldFocusLost

    private void payFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_payFieldFocusLost
        if(payField.getText().isEmpty()){
            payField.setText("Enter Pay Rate");
        }
    }//GEN-LAST:event_payFieldFocusLost

    private void deadlineFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_deadlineFieldFocusLost
        if(deadlineField.getText().isEmpty())
            deadlineField.setText("Enter Deadline");
    }//GEN-LAST:event_deadlineFieldFocusLost

    private void txtDescriptionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescriptionFocusLost
        if (txtDescription.getText().isEmpty())
            txtDescription.setText("Enter Job Description");
    }//GEN-LAST:event_txtDescriptionFocusLost

    private void txtRequirementsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtRequirementsFocusLost
        if (txtRequirements.getText().isEmpty())
            txtRequirements.setText("Enter Job Requirements");
    }//GEN-LAST:event_txtRequirementsFocusLost


    /**
     * Sets the network/connection and calls the main function.
     */
    public void connect() {
        try {
            net = Network.getInstance();
            btnCancel2.setEnabled(false);
            tabs.setSelectedIndex(1);
            tabs.setSelectedIndex(0);
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "No network connection established.");
        }
    }

    /**
     * Retrieves a list of all job postings in the database and displays them.
     */
    public void getPosts() {
        model = ((DefaultListModel)lstPostings.getModel());
        model.clear();

        try {
            net.out.Send(Packets.P_GETALLJOBS);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETALLJOBS)
                {
                        if(net.in.getDWord() != 0)
                        {
                            int jobNums = net.in.getDWord();
                            jobID = new ArrayList<Integer>();
                            
                            for(int i = 0; i < jobNums; i++)
                            {
                                jobID.add(net.in.getDWord());
                                model.add(i, net.in.getString());
                            }
                        }
                        else
                            JOptionPane.showMessageDialog(null, "Failed to retrieve job listing.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
    }

    /**
     * Retrieves specific job information and displays it.
     */
    public void getJob() {
           int selJobID = lstPostings.getSelectedIndex();

           if(selJobID!=-1){
            try {
                net.out.Insert(jobID.get(selJobID));
                net.out.Send(Packets.P_GETJOB);
                if (net.Ready())
                {
                    if (net.in.getPacketId() == Packets.P_GETJOB)
                    {
                        if(net.in.getDWord() != 0)
                        {
                            String jobTitle = net.in.getString();
                            String payRate = net.in.getString();
                            String Deadline = net.in.getString();
                            String Description = net.in.getString();
                            String Requirements = net.in.getString();

                            titleField.setText(jobTitle);
                            payField.setText(payRate);
                            deadlineField.setText(Deadline);
                            txtDescription.setText(Description);
                            txtRequirements.setText(Requirements);
                            lblID.setText(String.valueOf(jobID.get(selJobID)));
                        }
                        else
                            JOptionPane.showMessageDialog(null, "Failed to retrieve job information.");
                    }
                }
            }
            catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
            }
        }
        
    }

    /**
     * Retrieves a list of all job postings in the database and displays them.
     */
    public void getPosts1() {
        model = ((DefaultListModel)lstPostings1.getModel());
        model.clear();

        try {
            net.out.Send(Packets.P_GETALLJOBS);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETALLJOBS)
                {
                        if(net.in.getDWord() != 0)
                        {
                            int jobNums = net.in.getDWord();
                            jobID2 = new ArrayList<Integer>();

                            for(int i = 0; i < jobNums; i++)
                            {
                                jobID2.add(net.in.getDWord());
                                model.add(i, net.in.getString());
                            }
                        }
                        else
                            JOptionPane.showMessageDialog(null, "Failed to retrieve job listing.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
    }

    /**
     * Retrieves specific job information and displays it.
     */
    public void getJob1() {
        if(!((DefaultListModel)lstPostings1.getModel()).isEmpty()){
           int selJobID = lstPostings1.getSelectedIndex();

            try {
                net.out.Insert(jobID2.get(selJobID));
                net.out.Send(Packets.P_GETJOB);
                if (net.Ready())
                {
                    if (net.in.getPacketId() == Packets.P_GETJOB)
                    {
                        if(net.in.getDWord() != 0)
                        {
                            String jobTitle = net.in.getString();
                            String payRate = net.in.getString();
                            String Deadline = net.in.getString();
                            String Description = net.in.getString();
                            String Requirements = net.in.getString();

                            lblJobTitle1.setText(jobTitle);
                            lblID.setText(String.valueOf(jobID2.get(selJobID)));
                        }
                        else
                            JOptionPane.showMessageDialog(null, "Failed to retrieve job information.");
                    }
                }
            }
            catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
            }
           getApps(jobID2.get(selJobID));
           txtResume.setText("");
           txtReference1.setText("");
           txtReference2.setText("");
           txtReference3.setText("");
           txtComments.setText("");
        }
    }

    /**
     * Retrieves a list of all Applications in the database and displays them.
     */
    public void getApps(int jobID) {
        model = ((DefaultListModel)lstApplications.getModel());
        model.clear();

        try {
            net.out.Insert(jobID);
            net.out.Send(Packets.P_GETALLAPP);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETALLAPP)
                {
                        if(net.in.getDWord() != 0)
                        {
                            int appNums = net.in.getDWord();

                            for(int i = 0; i < appNums; i++)
                            {
                                appID.add(net.in.getDWord());
                                model.addElement(net.in.getString());
                            }
                        }
                        else
                            JOptionPane.showMessageDialog(null, "Failed to retrieve application listing.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
    }

    /**
     * Retrieves specific applicant information and displays it.
     */
    public void getApplication() {
       selectedApplicantID = lstApplications.getSelectedIndex();
       model = ((DefaultListModel)lstApplications.getModel());

        try {
            net.out.Insert(appID.get(selectedApplicantID));
            net.out.Send(Packets.P_GETAPPLICATION);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETAPPLICATION)
                {
                    if(net.in.getDWord() != 0)
                    {
                        int avgRating = net.in.getDWord();
                        int jID = net.in.getDWord();
                        String jobTitle = net.in.getString();
                        String applicantName = net.in.getString();
                        String email = net.in.getString();
                        String applicantResume = net.in.getString();
                        String referenceName1 = net.in.getString();
                        String referenceMessage1 = net.in.getString();
                        String referenceName2 = net.in.getString();
                        String referenceMessage2 = net.in.getString();
                        String referenceName3 = net.in.getString();
                        String referenceMessage3 = net.in.getString();

                        int revNums = net.in.getDWord();
                        revID = new ArrayList<Integer>();

                        lstReviewers.setModel(new DefaultListModel());
                        DefaultListModel tempM = (DefaultListModel) lstReviewers.getModel();
                            for(int i = 0; i < revNums; i++)
                            {
                                revID.add(net.in.getDWord());
                                tempM.addElement(net.in.getString());
                            }
                        
                        lblAvgRating.setText(String.valueOf(avgRating));
                        lblID.setText(String.valueOf(jID));
                        lblJobTitle.setText(jobTitle);
                        lblApplicantName.setText(applicantName);
                        lblEmail.setText(email);
                        txtResume.setText(applicantResume);
                        lblReference1.setText(referenceName1);
                        txtReference1.setText(referenceMessage1);
                        lblReference2.setText(referenceName2);
                        txtReference2.setText(referenceMessage2);
                        lblReference3.setText(referenceName3);
                        txtReference3.setText(referenceMessage3);
                    }
                    else
                        JOptionPane.showMessageDialog(null, "Failed to retrieve job information.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
    }

    /**
     * Retrieves specific application rating and displays it.
     */
    public void getRating() {
        int selRevID = lstReviewers.getSelectedIndex();
        if(selRevID != -1){
        try {

            net.out.Insert(revID.get(selRevID));
            net.out.Send(Packets.P_GETREVIEWRATING);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETREVIEWRATING)
                {
                    if(net.in.getDWord() != 0)
                    {
                        int rating = net.in.getDWord();
                        String comment = net.in.getString();

                        lblReviewerRating.setText("" + rating);
                        txtComments.setText(comment);
                    }
                    else
                        JOptionPane.showMessageDialog(null, "Failed to retrieve rating information.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
        }
    }

    /**
     * Retrieves a list of all accounts in the database and displays them.
     */
    public void getAccs() {
        model = ((DefaultListModel)lstAccounts.getModel());
        model.clear();

        try {
            net.out.Send(Packets.P_GETALLREVIEWERS);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETALLREVIEWERS)
                {
                        if(net.in.getDWord() != 0)
                        {
                            int revNums = net.in.getDWord();
                            revID2 = new ArrayList<Integer>();
                            
                            for(int i = 0; i < revNums; i++)
                            {
                                revID2.add(net.in.getDWord());
                                model.add(i, net.in.getString());
                            }
                        }
                        else
                            JOptionPane.showMessageDialog(null, "Failed to retrieve account listing.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
    }

    /**
     * Retrieves specific account information and displays it.
     */
    public void getAcc() {
       int selRevID = lstAccounts.getSelectedIndex();

        try {
            net.out.Insert(revID2.get(selRevID));
            net.out.Send(Packets.P_GETREVIEWER);
            if (net.Ready())
            {
                if (net.in.getPacketId() == Packets.P_GETREVIEWER)
                {
                    if(net.in.getDWord() != 0)
                    {
                        String username = net.in.getString();
                        String password = net.in.getString();

                        txtUsername.setText(username);
                        txtPassword.setText(password);
                        lblID1.setText(String.valueOf(revID2.get(selRevID)));
                    }
                    else
                        JOptionPane.showMessageDialog(null, "Failed to retrieve account information.");
                }
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error: " + e);
            e.printStackTrace();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnAddReviewer;
    private javax.swing.JButton btnApply;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnCancel2;
    private javax.swing.JButton btnSubmit;
    private javax.swing.JCheckBox chkDelete;
    private java.awt.TextField deadlineField;
    private javax.swing.JButton deleteReviewer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JLabel lblApplicantName;
    private javax.swing.JLabel lblAvgRating;
    private javax.swing.JLabel lblComments;
    private javax.swing.JLabel lblDeadline;
    private javax.swing.JLabel lblDescription;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblID;
    private javax.swing.JLabel lblID1;
    private javax.swing.JLabel lblJobID;
    private javax.swing.JLabel lblJobTitle;
    private javax.swing.JLabel lblJobTitle1;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblPay;
    private javax.swing.JLabel lblReference1;
    private javax.swing.JLabel lblReference2;
    private javax.swing.JLabel lblReference3;
    private javax.swing.JLabel lblRequirements;
    private javax.swing.JLabel lblResume;
    private javax.swing.JLabel lblReviewerRating;
    private javax.swing.JLabel lblUsername;
    private javax.swing.JList lstAccounts;
    private javax.swing.JList lstApplications;
    private javax.swing.JList lstPostings;
    private javax.swing.JList lstPostings1;
    private javax.swing.JList lstReviewers;
    private java.awt.TextField payField;
    private javax.swing.JButton subtractButton;
    private javax.swing.JTabbedPane tabs;
    private java.awt.TextField titleField;
    private javax.swing.JTextArea txtComments;
    private javax.swing.JTextArea txtDescription;
    private javax.swing.JTextField txtPassword;
    private javax.swing.JTextArea txtReference1;
    private javax.swing.JTextArea txtReference2;
    private javax.swing.JTextArea txtReference3;
    private javax.swing.JTextArea txtRequirements;
    private javax.swing.JTextArea txtResume;
    private javax.swing.JTextField txtUsername;
    // End of variables declaration//GEN-END:variables

}
